home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3195 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  76 lines

  1. Path: zetnet.co.uk!demon!stsdaveb.demon.co.uk
  2. From: dave@stsdaveb.demon.co.uk (Dave Thornton)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help!
  5. Date: Fri, 26 Jan 1996 15:55:12 GMT
  6. Organization: Severn Trent Systems
  7. Message-ID: <3108f3cd.14615158@news.demon.co.uk>
  8. References: <4ea5p4$j0s@ratree.psu.ac.th>
  9. NNTP-Posting-Host: stsdaveb.demon.co.uk
  10. X-NNTP-Posting-Host: stsdaveb.demon.co.uk
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. On 26 Jan 1996 09:09:56 GMT, s3610165@maliwan.psu.ac.th (Sanon
  14. CHAOCHAIYAPORN) wrote:
  15.  
  16. >Dear all
  17. >
  18. >    There is a file, hi.bat, in my 'h:\data' directory and I try to 
  19. >run it by C program but it fail. Please, advice to me?
  20. >
  21. >Source:
  22. >
  23. >#include<stdio.h>
  24. >#include<stdlib.h>
  25. >#include<conio.h>
  26. >#include<dir.h>
  27. >
  28. >main()
  29. >{
  30. >clrscr();
  31. >chdir("h:\data");
  32. >system("hi.bat");
  33. >getch()
  34. >}
  35.  
  36. >
  37. >
  38. >--
  39. >        ----------------------------------------------------------------
  40. >        |                              |                               |
  41. >        |  Sanon Chaochaiyaporn        |  Prince of Songkla University |
  42. >    |  s3610165@maliwan.psu.ac.th  |  Hadyai, Thailand             |
  43. >        |                              |                               |
  44. >    ----------------------------------------------------------------
  45.  
  46. Have you checked the return code of the chdir() function. It may not
  47. be changing into the directory. ie 
  48.  
  49. main( int argc, char * argv[])
  50. {
  51.     char * string = "Error Message";
  52.  
  53.     clrscr();
  54.  
  55.     if ( chdir("h:\data") == -1)
  56.     {
  57.         printf("Error changing to .\n");
  58.         perror(string);
  59.     }
  60.     else
  61.     {
  62.         system("hi.bat");
  63.         getch();
  64.     }
  65. }
  66.  
  67. Unfortunat;y there is no way to determine the exit status of the
  68. program run using system(). Use one of the spawn functions if an exit
  69. status is required.
  70.  
  71. Hope this is of use.
  72. -------------------------------------------------------------------------------
  73. | Dave Thornton    | email dave@stsdaveb.demon.co.uk                          |
  74. | Staffs, England  |                                                          |
  75. -------------------------------------------------------------------------------
  76.